package com.ruoyi.syf.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.annotation.ConvertField;
import com.ruoyi.common.annotation.ConvertFieldItem;
import com.ruoyi.common.enums.ConvertType;
import com.ruoyi.syf.common.constant.EscalationDataType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.syf.mapper.EscalationLogMapper;
import com.ruoyi.syf.domain.EscalationLog;
import com.ruoyi.syf.service.IEscalationLogService;

/**
 * 上报记录Service业务层处理
 *
 * @author yr
 * @date 2024-08-26
 */
@Service
public class EscalationLogServiceImpl extends ServiceImpl<EscalationLogMapper,EscalationLog> implements IEscalationLogService {
    @Autowired
    private EscalationLogMapper escalationLogMapper;

    @ConvertField({
            @ConvertFieldItem(fieldName = "type",
                    constantValue = {"0:通用", "1:http", "2:TCPSocket"}),
    })
    @Override
    public List<EscalationLog> list(EscalationLog escalationLog) {
        return escalationLogMapper.list(escalationLog);
    }

    @Override
    public int deleteEscalationLogByIds(Long[] ids) {
        return escalationLogMapper.deleteEscalationLogByIds(ids);
    }

    @Override
    public int deleteEscalationLogById(Long id) {
        return escalationLogMapper.deleteEscalationLogById(id);
    }

    @Override
    public EscalationLog getLastTimeLog(String escalationType) {
        return escalationLogMapper.getLastTimeLog(escalationType);
    }

    @Override
    public EscalationLog buildSucEscalationLog(String data, String type, String escalationType) {
        EscalationLog escalationLog = new EscalationLog();
        escalationLog.setType(type);
        escalationLog.setEscalationType(escalationType);
        escalationLog.setData(data);
        escalationLog.setStatus(true);
        escalationLog.setError(null);
        escalationLog.setMessage(null);
        return escalationLog;
    }

    @Override
    public EscalationLog buildErrEscalationLog(String data, String type, String escalationType, String error, String message) {
        EscalationLog escalationLog = new EscalationLog();
        escalationLog.setType(type);
        escalationLog.setEscalationType(escalationType);
        escalationLog.setData(data);
        escalationLog.setStatus(false);
        escalationLog.setError(error == null ? "上报配置信息不全" : error);
        escalationLog.setMessage(message == null ? "企业编码:COMPANY_CODE未完善!" : message);
        return escalationLog;
    }

}
